<template>
	<view class="repair">
		<head-class :moreList='moreList'></head-class>
		<empty v-if="repairList.list.length==0"></empty>
		<order-card :propsList='repairList' v-else></order-card>
	</view>
</template>

<script>
	import changetype from '../../utils/changetype.js'
	import empty from "../../components/empty.vue"
	import headClass from "@/components/head_class.vue"
	import orderCard from '@/components/orderCard.vue'
	export default {
		components: {
			orderCard,
			headClass,
			empty
		},
		data() {
			return {
				type: '', //类型
				moreList: '全部',
				baoxiuShow: ['指派给我', '进行中', '已完成', '全部工单', '待验收'],
				weibaoShow: ['指派给我', '进行中', '质保期内', '已完成', '全部工单', '待验收'],
				category: 0,
				repairList: {
					type: 'repair',
					list: []
				},
				current_page: 1,
				page: 1,
				data_status: 4

			}
		},
		onLoad(e) {
			this.type = e.type
			switch (e.type) {
				case "0":
					uni.setNavigationBarTitle({
						title: '报修工单'
					})
					break;
				case "1":
					uni.setNavigationBarTitle({
						title: '维保工单'
					})
					break;
				case "2":
					this.moreList = '质保期内',
						uni.setNavigationBarTitle({
							title: '质保期内'
						})
					break;

			}
			this.getData()
		},
		methods: {
			/* 详情跳转 */
			jump_detail(id) {
				uni.navigateTo({
					url: '../detail/detail?id=' + id
				})
			},
			/* 选择类目 */
			more() {
				if (this.type == '0') { //报修工单
					//状态:1=进行中，2=质保期内，3=已完成，0=指派给我,4=全部 5  待验收
					const obj = [{
							id: 0,
							ti: '指派给我'
						},
						{
							id: 1,
							ti: '进行中'
						},
						{
							id: 2,
							ti: '质保期内'
						},
						{
							id: 3,
							ti: '已完成'
						},
						{
							id: 4,
							ti: '全部工单'
						}, {
							id: 5,
							ti: '待验收'
						},
					]
					uni.showActionSheet({
						itemList: this.baoxiuShow,
						success: res => {
							this.moreList = this.baoxiuShow[res.tapIndex]
							let id_ = obj.find(item => {
								return item.ti == this.moreList
							})
							this.data_status = id_.id
							this.repairList.list = []
							this.page = 1
							this.last_page = 1
							this.getData()
						},
						fail: res => {
							console.log(res.errMsg);
						}
					});
				} else if (this.type == '1') {
					//状态:1=进行中，2=质保期内，3=已完成，0=指派给我,4=全部 5  待验收
					uni.showActionSheet({
						itemList: this.weibaoShow,
						success: res => {
							this.moreList = this.weibaoShow[res.tapIndex]
							this.data_status = res.tapIndex
							this.repairList.list = []
							this.page = 1
							this.last_page = 1
							this.getData()
						},
						fail: res => {
							console.log(res.errMsg);
						}
					});
				}

			},
			/* 获取数据 */
			getData() {
				let params = {}
				if (this.type == '0') {
					params = {
						status: this.data_status, //状态:1=进行中，2=质保期内，3=已完成，0=指派给我,4=全部 5待验收
						type: 0, //类型:3全部 0报修 1维保
						page: this.page
					}
				} else if (this.type == '1') {
					params = {
						status: this.data_status, //状态:1=进行中，2=质保期内，3=已完成，0=指派给我,4=全部 5待验收
						type: 1, //类型:3全部 0报修 1维保
						page: this.page
					}
				} else {
					params = {
						status: 2, //状态:1=进行中，2=质保期内，3=已完成，0=指派给我  4=全部 5待验收
						type: 0, //类型:3全部 0报修 1维保
						page: this.page
					}
				}
				this.$https.post('/warranty/engineerList', params).then(res => {
					if (res.data.last_page > 0) {
						this.last_page = res.data.last_page
						this.repairList.list = this.repairList.list.concat(res.data.data)
						this.repairList.list.forEach(item => {
							item.type_data = changetype(item.type_data)
						})
					}
				})
			}
		},
		onReachBottom() {
			if (this.page != this.last_page) {
				this.page = this.page + 1
				this.getData()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.repair {
		background-color: #f7f8fb;
		padding: 38rpx 32rpx;
		min-height: 100vh;
	}
</style>
